@echo off
echo ========================================
echo CFS Web System 部署脚本
echo ========================================

echo 1. 检查Python环境...
python --version
if %errorlevel% neq 0 (
    echo 错误: Python未安装或未添加到PATH
    pause
    exit /b 1
)

echo 2. 安装依赖包...
pip install -r requirements.txt
if %errorlevel% neq 0 (
    echo 错误: 依赖包安装失败
    pause
    exit /b 1
)

echo 3. 收集静态文件...
python manage.py collectstatic --noinput --settings=deploy.production_settings
if %errorlevel% neq 0 (
    echo 错误: 静态文件收集失败
    pause
    exit /b 1
)

echo 4. 执行数据库迁移...
python manage.py migrate --settings=deploy.production_settings
if %errorlevel% neq 0 (
    echo 错误: 数据库迁移失败
    pause
    exit /b 1
)

echo 5. 创建超级用户 (可选)...
set /p create_superuser=是否创建超级用户? (y/n): 
if /i "%create_superuser%"=="y" (
    python manage.py createsuperuser --settings=deploy.production_settings
)

echo 6. 启动服务器...
echo 生产环境启动命令:
echo python manage.py runserver 0.0.0.0:8000 --settings=deploy.production_settings
echo.
echo 或使用Gunicorn (推荐):
echo gunicorn cfs_web_system.wsgi:application --bind 0.0.0.0:8000 --workers 4
echo.
set /p start_server=是否立即启动开发服务器? (y/n): 
if /i "%start_server%"=="y" (
    python manage.py runserver 0.0.0.0:8000 --settings=deploy.production_settings
)

echo ========================================
echo 部署完成!
echo ========================================
pause